Metadata from IPBES on Zenodo

Author

Rainer M Krug

Back to the Repository

Setup and get records from Zenodo

Show the code
#|

# Load the zen4R library
library(zen4R)
library(openalexR)
Thank you for using openalexR!
To acknowledge our work, please cite the package by calling `citation("openalexR")`.
To suppress this message, add `openalexR.message = suppressed` to your .Renviron file.
Show the code
library(dplyr)

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
Show the code
fn <- file.path("data", "ipbes_zenodo_records")
if (!file.exists(paste0(fn, ".rds"))) {
    # Authenticate with Zenodo
    zen <- ZenodoManager$new(token = Sys.getenv("Zenodo_IPBES_RO"))

    # Get the community ID
    community_id <- "ipbes"

    # Get the community info
    community <- zen$getCommunityById(community_id)

    # Get all deposits with ipbes somwhere
    ipbes_zenodo <- zen$getRecords(community_id)

    # Filter records based on the community ID
    ipbes <- sapply(
        ipbes_zenodo,
        function(record) {
            "ipbes" %in% unlist(record$metadata$communities)
        }
    )

    ipbes_zenodo <- ipbes_zenodo[ipbes]

    rm(ipbes)

    saveRDS(ipbes_zenodo, paste0(fn, ".rds"))
} else {
    ipbes_zenodo <- readRDS(paste0(fn, ".rds"))
}

Get the dois and titles of the records

Show the code
dois <- data.frame()

for (i in seq(length.out = length(ipbes_zenodo))) {
    record <- ipbes_zenodo[[i]]
    dois <- rbind(
        dois,
        c(
            doi = record$metadata$doi,
            year = record$metadata$publication_date,
            title = record$metadata$title
        )
    )
}

names(dois) <- c("doi", "year", "title")

dois <- tibble::as_tibble(dois)
Show the code
#|
fn <- file.path(".", "data", "ipbes_works.rds")
if (!file.exists(fn)) {
    # Define the maximum chunk size
    chunk_size <- 50
    # Split the vector into chunks
    doi_chunks <- split(
        dois$doi,
        ceiling(seq_along(dois$doi) / chunk_size)
    )

    ipbes_works <- lapply(
        doi_chunks,
        function(dois) {
            openalexR::oa_query(doi = dois) |>
                openalexR::oa_request(count_only = FALSE)
        }
    ) |>
        unlist(recursive = FALSE)

    saveRDS(ipbes_works, file = fn)
} else {
    ipbes_works <- readRDS(file = fn)
}

IPBES deposits on Zenodo with OpenAlex ids

This is a quick and dirty table - it could made nicer - but it fulfills it’s purpose.

Show the code
ipbes_works |>
    openalexR::works2df() |>
    dplyr::select(
        # year = publication_year,
        # title,
        doi,
        oa_id = id
    ) |>
    dplyr::mutate(
        doi = gsub(pattern = "https://doi.org/", replacement = "", x = doi)
    ) |>
    dplyr::left_join(
        x = dois,
        by = c("doi" = "doi")
    ) |>
    dplyr::mutate(
        doi   = paste0("<a href='https://doi.org/", doi, "' target='_blank'>", doi, "</a>"),
        oa_id = ifelse(
            is.na(oa_id),
            "",
            paste0("<a href='", oa_id, "' target='_blank'>", gsub(pattern = "https://openalex.org/", replacement = "", oa_id), "</a>")
        )
    ) |>
    select(
        doi,
        oa_id,
        year,
        title
    ) |>
    IPBES.R::table_dt()